<?php
include_once("cIncludes.php");
session_start();
$kernel = new iKernel;

$pref = new DB("settings");
$pref->select();
$pref->nextRecord();

$url = new iUrl;

			if(!isset($url->page_url) || $url->page_url == ""){
				
				$db = new DB("cms_page");
				$db->setColPrefix("page_");
				$db->select("page_title='startpage'");
				
				$db->nextRecord();
				$db->control;
				$url->page_url = $db->title;
			}

		/*
		 * 
		 * Including and building Template Header
		 * 
		 */

		$head = new Template; 
		$head->settings = $pref; 
		$head->navigation = $kernel->navigation_module; 
		$head->Build("head_tpl");

		/*
		 * Including and building leftside Widgets
		 */

		 	$db = new DB("widgets");
			$db->select("widget_sidebar='left'");
			$db->setColPrefix("widget_");
			while($db->nextRecord()){
				include_once("widgets/".$db->name."/index.php");
				$class = $db->name."_widget";
				new $class;
			}
		 
	
		/*
		 * Including and building Template Content
		 */
		
		
			$main = new Template; 
			
		$db = new DB("cms_page");
		$db->setColPrefix("page_");
		$db->select("page_id='".$url->page_url."' or page_title='".$url->page_url."'");
		
		if($db->numRows() != "0"){
			$db->nextRecord();
			switch($db->control){
				case 'news':
						include("modules/news.php");
				break;
				case 'archive':
						include("modules/archive.php");
				break;				
				case 'custom':
						include("modules/custom.php");
				break;
			}
			$main->main_content = $content;
			$main->Build("main_tpl");
		}else{
			$main->main_content = "Page id not found";
			$main->Build("main_tpl");
		}

		/*
		 * Including and building rightside Widgets
		 */
		 	$db = new DB("widgets");
			$db->select("widget_sidebar='right'");
			$db->setColPrefix("widget_");
			while($db->nextRecord()){
				include_once("widgets/".$db->name."/index.php");
				$class = $db->name."_widget";
				new $class;
			}


		/*
		 * Including and building Template Footer
		 */
		$footer = new Template; 
		$footer->settings = $pref; 
		$footer->Build("footer_tpl");
